package diplomovka.subgraphSearcher.componentsFinder;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import diplomovka.subgraphSearcher.generated.SubgraphStatement;

public class SubgraphSearcher {

	public final static String SUBGRAPH_PATH = "../SubgraphSearcher/config/subgraph.xml";
	
	private SubgraphStatement subgraphStatement;
	
	public Map<String, List<Object>> searchComponentsInGraph(List<Object> graph) {
		
		initSubgraph();
		
		CartridgeFinder cartridgeFinder = new CartridgeFinderImpl(graph);
		return cartridgeFinder.findComponentsInGraph(subgraphStatement);
	}
	
	private void initSubgraph() {
		try {
			JAXBContext context = JAXBContext.newInstance("diplomovka.subgraphSearcher.generated");
			Unmarshaller unmarshaller = context.createUnmarshaller();
			subgraphStatement = (SubgraphStatement) unmarshaller.unmarshal(new File(SUBGRAPH_PATH));
		} catch (JAXBException e) {
			System.out.println("Can't create subgraph from given file.");
			System.out.println(e.getMessage());
		}
	}
}
